package ar.edu.caece.compiler.grammar.factories;

import ar.edu.caece.compiler.grammar.AbstractTokenVisitorFactory;
import ar.edu.caece.compiler.grammar.TokenVisitor;

public class PASOPAMFactory extends AbstractTokenVisitorFactory {

	private static PASOPAMFactory INSTANCE;
	
	private PASOPAM1Factory pasopam1Factory;
	private PASOPAM2Factory pasopam2Factory;

	private OTROSA2Factory otrosa2Factory;

	
	public static PASOPAMFactory getInstance() throws Exception {
		if(INSTANCE==null) INSTANCE = new PASOPAMFactory();
		return INSTANCE;
	}
	
	private Initializer initializer = new Initializer() {
		
		@Override
		public void init() throws Exception {
			initializer = NoOperationInitializer.getInstance();
			pasopam1Factory = PASOPAM1Factory.getInstance();
			pasopam2Factory = PASOPAM2Factory.getInstance();
			otrosa2Factory = OTROSA2Factory.getInstance();
		}
	};
	
	private PASOPAMFactory() throws Exception {

	}
	
	@Override
	public TokenVisitor makeChainedVisitor(
			final TokenVisitor siguiente) throws Exception {
		initializer.init();

		return pasopam1Factory.makeChainedVisitor( pasopam2Factory.makeChainedVisitor(otrosa2Factory.makeChainedVisitor(siguiente)));
	
	}
	@Override
	public TokenVisitor makeVisitor() throws Exception {
		initializer.init();

		return pasopam1Factory.makeChainedVisitor(pasopam2Factory.makeChainedVisitor(otrosa2Factory.makeVisitor()));
	}
	
	
}
